<?php
class item_unbanmember extends template_item
{
	var $default_name = "Unban a Member";
	var $default_description = "Use this item to unban a member";
	
	var $allow_multiple = 1;
	
	function public_use_form($inventory_ids = array())
	{
		$this->ipsclass->load_language('lang_market_items');
		
		$hidden_fields = $this->_get_hidden_fields($inventory_ids);
		
		return <<<EOF
<script type="text/javascript" src='jscripts/ipb_xhr_findnames.js'></script>
<div id='ipb-get-members' style='border:1px solid #000; background:#FFF; padding:2px;position:absolute;width:210px;display:none;z-index:1'></div>
<div class='formsubtitle'>{$this->ipsclass->lang['unban_an_user']}</div>
<form action='{$this->base_url}' method='post' id='changeform'>
{$hidden_fields}
	<table class='ipbtable' cellspacing='0' cellpadding='0'>
		<tr>
			<td class='row1' align='left'>
				<b>{$this->ipsclass->lang['which_member']}</b>
			</td>
			<td class='row2' align='right'>
				<input type='input' id='member_name' name='member_name' value='' size='30' class='forminput' autocomplete='off' style='width:210px' />
			</td>
		</tr>
		<tr>
			<td class='darkrow1' align='center' colspan='2'>
				<input type='submit' name='item_used' value='{$this->ipsclass->lang['unban_this_user']}' class='forminput' />
			</td>
		</tr>
	</table>
</form>
<script type="text/javascript">
	// INIT find names
	init_js( 'changeform', 'member_name');
	// Run main loop
	setTimeout( 'main_loop()', 10 );
</script>
EOF;
	}
	
	function input_done()
	{
		return isset($this->ipsclass->input['member_name']) && isset($this->ipsclass->input['item_used']);
	}
	
	function public_use_item($inventory_ids = array()) 
	{
		$this->ipsclass->load_language('lang_market_items');
		
		$member = $this->ipsclass->DB->build_and_exec_query(array('select'=>'*','from'=>'members','where'=>"members_l_display_name='".strtolower($this->ipsclass->input['member_name'])."'"));
		if(!$member['id'])
		{
			$this->ipsclass->Error(array('MSG'=>'no_user'));
		}
		
		$this->ipsclass->input['time'] = $this->ipsclass->numbers->parse_input_number($this->ipsclass->input['time'],'int');
		
		$this->ipsclass->DB->do_update('members',array(
															'temp_ban' => '',
									),"id=".$member['id']);
		
		$this->ipsclass->lang['other_member_unbanned'] = str_replace("<#NAME#>",$member['members_display_name'],$this->ipsclass->lang['other_member_unbanned']);
		
		$this->delete_items($inventory_ids);
		
		$inv_id = reset($inventory_ids);
		$this->_write_log($inv_id, "Unbanned <a href='{$this->ipsclass->base_url}showuser={$member['id']}'>{$member['members_display_name']}</a>");
		
		$this->ipsclass->market_class->redirect('other_member_unbanned');
	}
}
?>